<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/view/common/taglibs.jsp"%>
<!DOCTYPE html>
<html>
<meta charset="utf-8">
<head>
<title>${appname}-<c:if test="${!empty sessionScope._local_node_session}">${sessionScope._local_node_session.nodeName}-</c:if>${si:ctname("NET_TYPE",sessionScope._netType)}</title>
<%@ include file="/WEB-INF/view/common/css_js_ace.jsp"%>
<script type="text/javascript">
	jQuery(function($) {
		if('${param.queryType}'=='history'){
			$('#alert_ontime').removeClass("active");
			$('#alert_history').addClass("active");
			$('#batchClose').css("display","none");
	 	}else{
	 		$('#alert_ontime').addClass("active");
	 	   	$('#alert_history').removeClass("active");
	 	   $('#batchClose').css("display","");
	 	}
		$("#"+$("#type").val()).css("display","");
	});
	function closeById(id){
		ui.confirm('确认关闭?',function(){
			$.ajax({
				   type: "POST",
				   dataType:"json",
				   cache: false,
				   url: _ctx + "/exch/close_alert.do",
				   data: {id:id},
				   success: function(resp){
					   if(resp.status == '1'){
						   ui.msg(resp.msg, 1);
						   ui.go(_ctx + '//exch/alert_list.do?queryType='+$("#queryType").val());
					   }else{
						   ui.msg(resp.msg, 0);
					   }
				   },
				   error:function(){
					   ui.msg('信息加载错误', 0);
				   }
			});
		});	
	}
	/**
	批量删除
	**/
	function batchClose(){
		var ids = $("input[name='ids']:checked");//jquery语法，选择页面中所有input表单中name=ids且被选中的值
		if(ids.length == 0){
			alert('请选择要关闭的告警!');
			return;
		}	
		
		var validIds = new Array();
		var idAndStatus = null;
		var id = null;
		var status = null;
		for(var i=0;i<ids.length;i++){
			validIds.push($(ids[i]).val());
		}
		var idsVal = "";
		for(var i=0;i<validIds.length;i++){
			idsVal += validIds[i] +",";
		}
		idsVal = idsVal.substring(0,idsVal.length - 1);
		ui.confirm('确认关闭?',function(){
			$.ajax({
				   type: "POST",
				   dataType:"json",
				   cache: false,
				   url: _ctx + "/exch/batch_close_alert.do",
				   data: {"ids":idsVal},
				   success: function(resp){
					   if(resp.status == '1'){
						   ui.msg(resp.msg, 1);
						   ui.go(_ctx + '//exch/alert_list.do?queryType='+$("#queryType").val());
					   }else{
						   ui.msg(resp.msg, 0);
					   }
				   },
				   error:function(){
					   ui.msg('信息加载错误', 0);
				   }
			});
		});	
	}
	function change(){
		$("#node").css("display","none");
		$("#domain").css("display","none");
		$("#adapter").css("display","none");
		$("#"+$("#type").val()).css("display","");
		if($("#type").val() == "node"){
			$("#ownerId").val('${node.id }');
		}else{
			$("#"+$("#type").val()+" option:first").prop("selected", 'selected');
			$("#ownerId").val($("#"+$("#type").val()).val());
			
		}
	}
	function changeDomain(){
		$("#ownerId").val($("#domain").val());
	}
	function changeAdapter(){
		$("#ownerId").val($("#adapter").val());
	}
	 function alertList(queryType){
		 $("#queryType").val(queryType);
		 if(queryType=='history'){
				$('#alert_ontime').removeClass("active");
				$('#alert_history').addClass("active");
				$('#batchClose').css("display","none");
		 	}else{
		 		$('#alert_ontime').addClass("active");
		 	   	$('#alert_history').removeClass("active");
		 	   $('#batchClose').css("display","");
		 	}
		$("#searchForm").submit();
	}
	 function search(form) {
			$(form).appendPagerParaStr();
			return true;
	}
</script>
</head>
<body>
	<%@ include file="/WEB-INF/view/common/topbar.jsp"%>
	<div class="main-container" id="main-container">
		<div class="main-container-inner">
			<%@ include file="/WEB-INF/view/common/sidebar.jsp"%>
			<div class="main-content">
				<div class="breadcrumbs" id="breadcrumbs">
					<ul class="breadcrumb">
						<li><i class="icon-home home-icon"></i> <a href="#">首页</a>
						</li>
						<li>
							<a href="#">交换管理</a>
						</li>
						<li><a href="#">告警管理</a>
						</li>
						<li class="active">列表</li>
					</ul>
				</div>
				<div class="page-content">
					<div class="row">
						<div class="col-xs-12">
							<div class="widget-box">
								<div class="widget-header header-color-white">
									<div class="widget-toolbar no-border">
										<a id = "batchClose" class="btn btn-primary btn-xs" href="javascript:batchClose();"><i class="icon-mail-reply-all icon-on-right"></i> 批量关闭&nbsp;&nbsp;</a> 
										<a href="#" data-action="collapse"><i class="icon-chevron-up"></i></a>
									</div>
								</div>
								<div class="widget-body">
									<div class="widget-main">
										<form id="searchForm" class="form-search"
											action="${ctx }/exch/alert_list.do" method="post"
											onsubmit="return search(this)">
											<div class="row">
												<div class="col-xs-3">
													<div class="input-group">
														<span class="input-group-addon">告警级别</span> 
														<select class="form-control search-query" id="alterLevel"
															name="alterLevel" >
															<option value="">全部</option>
												    		${si:ctoption("ALTER_LEVEL", param.alterLevel) }
												    	</select>
													</div>
												</div>
												<c:if test="${sessionScope._user_session.slAuthFlag ne 4 }">
													<div class="col-xs-3">
														<div class="input-group">
															<span class="input-group-addon">监控级别</span> 
															<select
																class="form-control search-query" id="type" name="type"
																onchange="change();">
																<option value="" <c:if test="${monitType eq 'null'}">selected</c:if>>全部</option>
																<option value="node" <c:if test="${monitType eq 'node'}">selected</c:if>>节点</option>
																<option value="domain" <c:if test="${monitType eq 'domain'}">selected</c:if>>域</option>
																<option value="adapter" <c:if test="${monitType eq 'adapter'}">selected</c:if>>适配器</option>
															</select>
														</div>
													</div>
												</c:if>
												<div class="col-xs-4">
													<div class="input-group ">
														<select class="form-control search-query" id="domain"
															name="domain" onchange="changeDomain();"
															style="display: none;">
															<c:forEach var="domain" items="${ domainList}">
																<option value="${domain.id }" <c:if test="${domain.id eq monitOwnerId}">selected</c:if>>${domain.name }</option>
															</c:forEach>
														</select> 
														<select class="form-control search-query" id="adapter"
															name="adapter" onchange="changeAdapter();" style="display: none;">
															<c:forEach var="adapter" items="${ adapterList}">
																<option value="${adapter.id }" <c:if test="${adapter.id eq monitOwnerId}">selected</c:if>>${adapter.adapterName }</option>
															</c:forEach>
														</select> 
														<span class="input-group-btn">
															<button type="sumbit" class="btn btn-purple btn-sm" style="height:32px;" >
																<i class="icon-search icon-on-right bigger-110"></i> 搜索
															</button>
														</span>
														<input type="hidden" id="queryType" name="queryType" value="${param.queryType }">
														<input type="hidden" id="ownerId" name="ownerId" value="${ param.ownerId}">
													</div>
												</div>
										</form>
									</div>
								</div>
							</div>
							<div class="hr hr12 hr-dotted"></div>
							<div class="row">
								<div class="col-md-8">
									<ul class="nav nav-tabs">
										<li id="alert_ontime"><a href="javascript:void(0);"
											class="navbar-link" onclick="alertList('ontime');">待处理告警</a>
										</li>
										<li id="alert_history"><a href="javascript:void(0);"
											class="navbar-link" onclick="alertList('history');">已处理告警</a>
										</li>
									</ul>
								</div>
							</div>
							<div class="table-responsive">
								<table class="table table-striped table-bordered table-hover">
									<thead>
										<tr>
											<c:if test="${param.queryType ne 'history'}">
											<th width="2%"><input type="checkbox" name="cka"
												onclick="$.checkBoxTriggerAll(this,'ids')" />
											</th>
											</c:if>
											<th class="center">序号</th>
											<th>指标项</th>
											<th>告警信息</th>
											<th>告警级别</th>
											<th>告警时间</th>
												<c:if test="${param.queryType eq 'history' }">
													<th>处理方法</th>
													<th>处理时间</th>
												</c:if>
												<c:if test="${param.queryType ne 'history' }">
													<th>操作</th>
												</c:if>
										</tr>
									</thead>
									<tbody>
										<c:forEach var="vo" items="${_data}" varStatus="idx">
											<tr>
											<c:if test="${param.queryType ne 'history'}">
												<td align="center"><input name="ids" type="checkbox"
													value="${vo.id}" />
												</td>
												</c:if>
												<td class="center">${idx.index + 1}</td>
												<td>${vo.quotaName}</td>
												<td>${vo.alertMsg}</td>
												<td>${si:ctname("ALTER_LEVEL",vo.alterLevel )}</td>
												<td>${si:fmtDate(vo.mtime)}</td>
												<c:if test="${param.queryType eq 'history' }">
														<td>${si:ctnameMulti("ALERT_PIPELINE",vo.hasAlertMethod) }</td>
														<td>${si:fmtDate(vo.handlerTime)}</td>
													</c:if>
													<c:if test="${param.queryType ne 'history' }">
														<td>
															<div
																class="visible-md visible-lg hidden-sm hidden-xs action-buttons">
																<a class="red" href="javascript:void(0);"
																	onclick="closeById('${vo.id}');" title="关闭"> <i
																	class="icon-eye-close bigger-130"></i> </a>
															</div></td>
													</c:if>
											</tr>
										</c:forEach>
									</tbody>
								</table>
								<jsp:include page="/WEB-INF/view/common/pg.jsp">
									<jsp:param value="${ctx }/exch/alert_list.do" name="url" />
									<jsp:param value="${_total}" name="total" />
									<jsp:param value="${_urlpara}" name="urlpara" />
								</jsp:include>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</body>
</html>
